<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>个人中心</title>
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        /* 用户信息 */
        .user-info-head {
            width: 110px;
            height: 110px;
            line-height: 110px;
            position: relative;
            display: inline-block;
            border: 2px solid #eee;
            border-radius: 50%;
            overflow: hidden;
            cursor: pointer;
            margin: 0 auto;
        }

        .user-info-head:hover:after {
            content: '\e681';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            color: #fff;
            background-color: rgba(0, 0, 0, 0.3);
            font-size: 28px;
            padding-top: 2px;
            font-style: normal;
            font-family: layui-icon;
            -webkit-font-smoothing: antialiased;
            -moz-osx-font-smoothing: grayscale;
        }

        .user-info-head img {
            width: 110px;
            height: 110px;
        }

        .user-info-list-item {
            position: relative;
            padding-bottom: 8px;
        }

        .user-info-list-item > .layui-icon {
            position: absolute;
        }

        .user-info-list-item > p {
            padding-left: 30px;
        }

        .layui-line-dash {
            border-bottom: 1px dashed #ccc;
            margin: 15px 0;
        }

        /* 基本信息 */
        #userInfoForm .layui-form-item {
            margin-bottom: 25px;
        }

        /* 账号绑定 */
        .user-bd-list-item {
            padding: 14px 60px 14px 10px;
            border-bottom: 1px solid #e8e8e8;
            position: relative;
        }

        .user-bd-list-item .user-bd-list-lable {
            color: #333;
            margin-bottom: 4px;
        }

        .user-bd-list-item .user-bd-list-oper {
            position: absolute;
            top: 50%;
            right: 10px;
            margin-top: -8px;
            cursor: pointer;
        }

        .user-bd-list-item .user-bd-list-img {
            width: 48px;
            height: 48px;
            line-height: 48px;
            position: absolute;
            top: 50%;
            left: 10px;
            margin-top: -24px;
        }

        .user-bd-list-item .user-bd-list-img + .user-bd-list-content {
            margin-left: 68px;
        }

        .text-center {
            text-align: center;
        }
    </style>
</head>

<body>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <!-- 左 -->
        <div class="layui-col-sm12 layui-col-md3">
            <div class="layui-card">
                <div class="layui-card-body" style="padding: 25px;">
                    <div class="text-center layui-text">
                        <div class="user-info-head" id="userInfoHead">
                            <img src="${sessionScope.adminDesc.logoPath}" alt="" id="ID-upload-demo-img"/>
                        </div>
                        <h2 style="padding-top: 20px;">${requestScope.admin.username}</h2>
                        <p style="padding-top: 8px;">${requestScope.admin.adminDesc.content}</p>
                    </div>
                    <div class="layui-text" style="padding-top: 30px;">
                        <div class="user-info-list-item">
                            <i class="layui-icon layui-icon-username"></i>
                            <p>${requestScope.admin.adminDesc.nickname}</p>
                        </div>
                        <div class="user-info-list-item">
                            <i class="layui-icon layui-icon-release"></i>
                            <p>${requestScope.admin.adminDesc.job}</p>
                        </div>
                    </div>
                    <div class="layui-line-dash"></div>
                    <h3>标签</h3>
                    <div class="layui-badge-list" style="padding-top: 6px;">
                        <c:forEach items="${requestScope.admin.adminDesc.tags.split(',')}" var="tag">
                            <span class="layui-badge layui-bg-gray">${tag}</span>
                        </c:forEach>
                    </div>
                </div>
            </div>
        </div>
        <!-- 右 -->
        <div class="layui-col-sm12 layui-col-md9">
            <div class="layui-card">
                <!-- 选项卡开始 -->
                <div class="layui-tab layui-tab-brief" lay-filter="userInfoTab">
                    <ul class="layui-tab-title">
                        <li class="layui-this">基本信息</li>
                    </ul>
                    <div class="layui-tab-content">
                        <!-- tab1 -->
                        <div class="layui-tab-item layui-show">
                            <form class="layui-form" id="userInfoForm" lay-filter="userInfoForm"
                                  style="max-width: 400px;padding: 25px 10px 0 0;">
                                <input type="hidden" name="adminDescId" value="${sessionScope.adminDesc.id}">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">邮箱</label>
                                    <div class="layui-input-block">
                                        <input name="email"  id="email" type="email" class="layui-input" maxlength="30"
                                               lay-verType="tips" lay-verify="email" required/>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label layui-form-required">昵称:</label>
                                    <div class="layui-input-block">
                                        <input name="nickname" id="nickname" value="Serati Ma" class="layui-input"
                                               lay-verify="required" required/>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">手机号</label>
                                    <div class="layui-input-block">
                                        <input name="phone"  id="phone" type="text" class="layui-input" maxlength="20"
                                               lay-verType="tips" lay-verify="phone" required/>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">职位:</label>
                                    <div class="layui-input-block">
                                        <input name="job" id="job" class="layui-input" placeholder="某某公司－某某技术部－CEO"/>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">个人标签:</label>
                                    <div class="layui-input-block">
                                        <input name="tags" id="tags" value="" class="layui-input" placeholder="逗号分割"/>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">个人简介:</label>
                                    <div class="layui-input-block">
                                        <textarea name="content" id="content" placeholder="个人简介" class="layui-textarea"></textarea>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <button class="layui-btn" lay-filter="userInfoSubmit" lay-submit>更新基本信息
                                        </button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
                <!-- //选项卡结束 -->
            </div>
        </div>
    </div>
</div>

<!-- js部分 -->
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="/js/sessionTimout.js" charset="utf-8"></script>
<script>
    layui.use(['layer', 'form','upload'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var upload = layui.upload;
        $.get('/AdminServlet?opt=info',function (res){
            let data = res.data
            $('#email').val(data.email)
            $('#nickname').val(data.nickname)
            $('#phone').val(data.phone)
            $('#job').val(data.job)
            $('#tags').val(data.tags)
            $('#content').val(data.content)
            form.render();
        },"json")
        /* 选择头像 */
        upload.render({
            elem: '#userInfoHead',
            url: '/AdminServlet?opt=upload',
            before: function (obj) {
                layer.msg('上传中', {icon: 16, time: 0});
            },
            done: function (res) {
                // 若上传失败
                if (res.code == 1) {
                    return layer.msg('上传失败', {icon: 2});
                } else {
                    $('#ID-upload-demo-img').attr('src', res.data + '?r = Math.random()'); // 图片链接刷新
                    return layer.msg('上传成功', {icon: 1});
                }
            }
        });

        /* 监听表单提交 */
        form.on('submit(userInfoSubmit)', function (data) {
            $.ajax({
                url: '/AdminServlet?opt=update',
                type: "POST",
                data: data.field,
                dataType: "json",
                success: function (data) {
                    layer.closeAll('loading');
                    if (data.code == 0) {
                        layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                            location.reload(); // 刷新页面
                        });
                    } else {
                        layer.msg(data.msg, {icon: 2});
                    }
                }
            })
            return false;
        });

    });
</script>
</body>

</html>